<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>后台管理</title>
{{include file="layouts/_head"}}
</head>
<body>
<div class="main">
    <ol class="breadcrumb">
        <li><i class="icon_home iconfont"></i>首页</li>
        <li>订单物流</li>
        <li><a href="javascript:history.go(-1);">订单管理</a></li>
        <li class="active">订单详情</li>
    </ol>
    <div class="main-con">
        <div class="row">
            <div class="col-xs-6">
                <p style="font-size: 16px"><strong>信息总览</strong></p>
                <table class="table table-bordered table-hover">
                    <tbody>
                        <tr>
                            <td><strong>订单 ID</strong></td>
                            <td class="text-left">{{$order.id}}</td>
                        </tr>
                        <tr>
                            <td><strong>订单编号</strong></td>
                            <td class="text-left">{{$order.number}}</td>
                        </tr>
                        <tr>
                            <td><strong>用户昵称</strong></td>
                            <td class="text-left">{{$order.user_nickname}}</td>
                        </tr>
                        <tr>
                            <td><strong>支付方式</strong></td>
                            <td class="text-left">{{$order.payment_name}}</td>
                        </tr>
                        <tr>
                            <td><strong>购买方式</strong></td>
                            <td class="text-left">{{$order.type_str}}</td>
                        </tr>
                        <tr>
                            <td><strong>总金额</strong></td>
                            <td class="text-left">¥ {{$order.total_price}}</td>
                        </tr>
                        <tr>
                            <td><strong>订单状态</strong></td>
                            <td class="text-left">{{$order.status_str}}</td>
                        </tr>
                        <tr>
                            <td><strong>创建时间</strong></td>
                            <td class="text-left">{{$order.create_time}}</td>
                        </tr>
                    </tbody>
                </table>
                <p style="font-size: 16px"><strong>订单状态</strong></p>
                <table class="table table-bordered table-hover">
                    <thead class="bg-1">
                        <tr>
                            <th>订单状态</th>
                            <th>操作 <i class="iconfont iconfont-question" data-toggle="tooltip" data-placement="top" data-original-title="点击该按钮查看详情" onclick="orderActionInfo();"></i></th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td><strong>{{$order.status_str}}</strong></td>
                            <td>
                                {{if $order.status == 10 || ($order.status == 20 && $order.payment_id == 5)}}
                                <button type="button" class="btn btn-danger btn-xs" onclick="setOrderStatus({{$order.id}}, '-10')">取消订单</button>
                                {{/if}}
                                {{if $order.status == 20}}
                                <button type="button" class="btn btn-primary btn-xs" onclick="layerOpen('/admin/order/shipment.html?order_id={{$order.id}}', '发货', '840px', '400px')" >确认发货</button>
                                <button type="button" class="btn btn-danger btn-xs" onclick="setOrderStatus({{$order.id}}, '-10')">取消订单</button>
                                {{/if}}
                                {{if $order.status == 30}}
                                <button type="button" class="btn btn-success btn-xs" onclick="setOrderStatus({{$order.id}}, '40')">确认收货</button>
                                <button type="button" class="btn btn-danger btn-xs" onclick="setOrderStatus({{$order.id}}, '-10')">取消订单</button>
                                {{/if}}
                                {{if $order.status == 40}}
                                <button type="button" class="btn btn-danger btn-xs" onclick="setOrderStatus({{$order.id}}, '-10')">取消订单</button>
                                {{/if}}
                                {{if $order.status == '-10'}}
                                无操作选项
                                {{/if}}
                            </td>
                        </tr>
                    </tbody>
                </table>
                {{if $order.status >= 30}}
                <p style="font-size: 16px"><strong>物流信息</strong></p>
                <table class="table table-bordered table-hover">
                    <thead class="bg-1">
                        <tr>
                            <th>配送方式</th>
                            <th>快递单号</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>{{$order.tracking.shipping_mark_name}}</td>
                            <td>{{$order.tracking.tracking_number}}</td>
                        </tr>
                    </tbody>
                </table>
                {{/if}}
             </div>
             <div class="col-xs-6">
                <p style="font-size: 16px"><strong>收货地址</strong></p>
                <table class="table table-bordered table-hover">
                    <tbody>
                        <tr>
                            <td><strong>收货人姓名</strong></td>
                            <td class="text-left">{{$order.name}}</td>
                        </tr>
                        <tr>
                            <td><strong>联系方式</strong></td>
                            <td class="text-left">{{$order.phone}}</td>
                        </tr>
                        <tr>
                            <td><strong>详细地址</strong></td>
                            <td class="text-left">{{$order.province_name}} {{$order.city_name}} {{$order.district_name}} {{$order.detailed_address}}</td>
                        </tr>
                    </tbody>
                </table>
                
                <p style="font-size: 16px"><strong>买家信息</strong></p>
                <table class="table table-bordered table-hover">
                    <tbody>
                        <tr>
                            <td><strong>用户昵称</strong></td>
                            <td class="text-left">{{$user.nickname}}</td>
                        </tr>
                        <tr>
                            <td><strong>Email</strong></td>
                            <td class="text-left">{{$user.email ? $user.email : '无'}}</td>
                        </tr>
                        <tr>
                            <td><strong>联系方式</strong></td>
                            <td class="text-left">{{$user.phone}}</td>
                        </tr>
                        <tr>
                            <td><strong>性别</strong></td>
                            <td class="text-left">{{$user.sex_str}}</td>
                        </tr>
                        <tr>
                            <td><strong>账户余额</strong></td>
                            <td class="text-left">{{$user.wallet}}</td>
                        </tr>
                        <tr>
                            <td><strong>注册时间</strong></td>
                            <td class="text-left">{{$user.create_time}}</td>
                        </tr>
                    </tbody>
                </table>
                <p style="font-size: 16px"><strong>用户留言</strong></p>
                <table class="table table-bordered table-hover">
                    <tbody>
                        <tr>
                            <td class="text-left">{{if(!empty($order.message))}} {{$order.message}} {{else}} 暂无留言！ {{/if}}</td>
                        </tr>
                    </tbody>
                </table>
             </div>
        </div>   
        <p style="font-size: 16px"><strong>交易快照</strong></p>
        <table class="table table-bordered table-hover">
            <thead class="bg-1">
                <tr>
                    <th>产品 ID</th>
                    <th>SKU</th>
                    <th>封面图</th>
                    <th>产品名</th>
                    <th>销售规格</th>
                    <th>成交单价</th>
                    <th>购买数量</th>
                    <th>总金额</th>
                </tr>
            </thead>
            <tbody>
                {{volist name="order.snaps" id="vo" key="key"}}
                <tr>
                    <td>{{$vo.product_id}}</td>
                    <td>{{$vo.sku}}</td>
                    <td><img src="{{$vo.product_image}}" class="wh-50x50" /></td>
                    <td>{{$vo.product_name}}</td>
                    <td>
                        {{volist name="$vo.specifications" id="vo_specification"}}
                        <span class="margin-r-3">{{$vo_specification.specification_option_value}}</span>
                        {{/volist}}
                    </td>
                    <td>¥ {{$vo.sale_price}}</td>
                    <td>{{$vo.count}}</td>
                    <td>¥ {{$vo.total_price}}</td>
                </tr>
                {{/volist}}
                <tr>
                    <td colspan="7"></td>
                    <td>运费：¥ {{$order.shipping_freight_total_price}}</td>
                </tr>
                <tr>
                    <td colspan="7"></td>
                    <td>总金额：¥ {{$order.total_price}}</td>
                </tr>
            </tbody>
        </table>
    </div>
</div>
{{include file="layouts/_foot"}}
</body>
<script type="text/javascript">
function setOrderStatus(order_id, status)
{
    layer.confirm('确认操作？', function(index) {
        layer.closeAll(); var load = layer.load();
        $.ajax({
            url: '{{:url("/admin/order/setOrderStatus")}}?order_id='+order_id+'&status='+status,
            type: 'GET',
            success: function(res) {
                layer.close(load);
                if (res.code == 401) {
                    goLogin(); return false;
                }
                if (res.code == 200) {
                    layer.msg('操作成功', { time: 1500 }, function () { window.location.reload(); });
                } else if (res.code == 400) {
                    layer.msg(res.message); return false;
                } else {
                    layer.msg('操作失败'); return false;
                }
            }
        })
    })
}

function orderActionInfo()
{
    let str = '';
    str += '<div style="padding: 15px">';
    str += '<p><b>取消订单</b>：当订单状态为已取消之外的状态时，后台可手动取消该订单。</p>';
    str += '<p><b>确认发货</b>：当订单状态为待发货时，后台可操作订单发货。点击确认发货按钮，在新打开的发货页面选择配送方式，并填写快递单号。</p>';
    str += '<p><b>确认收货</b>：当订单状态为待收货时，后台可手动修改订单状态为待收货。</p>';
    str += '<hr/>';
    str += '<p>详情点击查看 <a href="https://www.yuque.com/luckmall/ukqmgh/ze86q7" target="_blank">帮助文档</a></p>';
    str += '</div>';
    layer.open({
        type: 1, 
        title: '操作说明',
        area: ['500px', '250px'],
        maxmin: true,
        content: str,
    });
}
</script>
</html>